Implement duplication of Alt-dragged layers within the Layers panel#2847
Implement duplication of Alt-dragged layers within the Layers panel#2847sneaxhuh wants to merge 3 commits into
Conversation
ec51271 to
e025103
Compare
|
Hi @Keavon , can you please review this. Thanks |
|
Will do, no promises on when though. Still backlogged on code reviews. |
|
@Keavon , just a gentle reminder |
| if as_duplicate { | ||
| let mut all_new_ids = Vec::new(); | ||
| let selected_layers = self.network_interface.selected_nodes().selected_layers(self.metadata()).collect::<Vec<_>>(); | ||
|
|
||
| responses.add(DocumentMessage::DeselectAllLayers); | ||
| responses.add(DocumentMessage::AddTransaction); | ||
|
|
||
| for selected_layer in selected_layers { | ||
| let layer_node_id = selected_layer.to_node(); | ||
|
|
||
| let mut copy_ids = HashMap::new(); | ||
| copy_ids.insert(layer_node_id, NodeId(0)); | ||
|
|
||
| self.network_interface | ||
| .upstream_flow_back_from_nodes(vec![layer_node_id], &[], network_interface::FlowType::LayerChildrenUpstreamFlow) | ||
| .enumerate() | ||
| .for_each(|(index, node_id)| { | ||
| copy_ids.insert(node_id, NodeId((index + 1) as u64)); | ||
| }); | ||
|
|
||
| let nodes: Vec<_> = self.network_interface.copy_nodes(©_ids, &[]).collect(); | ||
| let new_ids: HashMap<_, _> = nodes.iter().map(|(id, _)| (*id, NodeId::new())).collect(); | ||
| let layer = LayerNodeIdentifier::new_unchecked(new_ids[&NodeId(0)]); | ||
| all_new_ids.extend(new_ids.values().cloned()); | ||
|
|
||
| responses.add(NodeGraphMessage::AddNodes { nodes, new_ids: new_ids.clone() }); | ||
| responses.add(NodeGraphMessage::MoveLayerToStack { layer, parent, insert_index }); | ||
| } | ||
|
|
||
| responses.add(NodeGraphMessage::RunDocumentGraph); | ||
| responses.add(NodeGraphMessage::SelectedNodesSet { nodes: all_new_ids }); | ||
|
|
||
| return; | ||
| } |
There was a problem hiding this comment.
I have consolidated your new logic into the existing layer move message. Please see if you can further consolidate the logic to share code paths wherever possible. Because currently this just takes your duplicate-ish implementation and pastes it into here (followed by an early return; to avoid running the subsequent original non-duplication code paths).
| isDuplicating = event.altKey; | ||
| event.dataTransfer.dropEffect = isDuplicating ? "copy" : "move"; | ||
| event.dataTransfer.effectAllowed = isDuplicating ? "copy" : "move"; |
There was a problem hiding this comment.
Please get this to update the cursor icon while dragging so the user can add or remove Alt any number of times during a drag and watch as the cursor updates, and the final state when the mouse drag is released becomes whether or not to duplicate. So the user can decide at the time of mouseup, not mousedown, whether to duplicate.
|
Any updates? Just a reminder. |
124235a to
a42cad8
Compare
This PR introduces the ability to duplicate selected layers within the editor. Users can now duplicate layers by dragging them while holding the Alt key.
This includes:
Adding a new DuplicateSelectedLayers message.
Implementing the logic to copy and insert duplicated layers into the document.
Updating the frontend to detect the Alt key during drag operations and trigger the duplication.
Exposing the duplicateLayer function in the WASM API.